package me.ingxin.android.permission2.ext

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import androidx.annotation.RequiresApi
import me.ingxin.android.permission2.PERMISSION_REQUEST_INSTALL_PACKAGES
import me.ingxin.android.permission2.targetSdkVersion

/**
 * Created on 2023/7/12 by yin
 * android.permission.REQUEST_INSTALL_PACKAGES
 */
internal class InstallPackagesPermissionTask : BaseSpecialPermissionsTask() {

    override val permission = PERMISSION_REQUEST_INSTALL_PACKAGES

    override fun showRequestPermission(context: Context): Boolean {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && context.targetSdkVersion >= Build.VERSION_CODES.O
    }

    @RequiresApi(Build.VERSION_CODES.O)
    override fun crateInput(context: Context): Intent {
        return Intent(
            Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, Uri.parse("package:${context.packageName}")
        )
    }

}